const logger = require('./logger.lib');

class Interceptor {
    constructor() {
    }
    notFound(ctx) {

    }
    async error(ctx, next) {
        try {
            await next();
        } catch (err) {
            logger.error.error(err);
        }
    }

    /**
     * 设置参数函数
     */
    setParameter() {
        return function (ctx, next) {
            if (ctx.getParameter) {
                return next();
            }
            ctx.getParameter = function (key) {
                return this.query[key] || this.params[key] || this.request.body[key];
            }
            return next();
        }
    }
}

module.exports = global.buildClass(Interceptor)